
package common.packet;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 *
 * @author xissburg
 */
public class BodyState implements Packet
{
    public String name;
    public float posX, posY;
    public float angle;
    public float linVelX, linVelY;
    public float angVel;
    public float forceX, forceY;
    public float torque;

    public BodyState() {
        this("");
    }

    public BodyState(String name)
    {
        this.name = name;
        posX = posY = 0;
        angle = 0;
        linVelX = linVelY = 0;
        angVel = 0;
        forceX = forceY = 0;
        torque = 0;
    }

    public BodyState(BodyState bodyState)
    {
        name = bodyState.name;
        posX = bodyState.posX;
        posY = bodyState.posY;
        angle = bodyState.angle;
        linVelX = bodyState.linVelX;
        linVelY = bodyState.linVelY;
        angVel = bodyState.angVel;
        forceX = bodyState.forceX;
        forceY = bodyState.forceY;
        torque = bodyState.torque;
    }

    public BodyState(DataInputStream in) throws IOException {
        read(in);
    }

    public void read(DataInputStream in) throws IOException {
        name = in.readUTF();
        posX = in.readFloat(); posY = in.readFloat();
        angle = in.readFloat();
        linVelX = in.readFloat(); linVelY = in.readFloat();
        angVel = in.readFloat();
        forceX = in.readFloat(); forceY = in.readFloat();
        torque = in.readFloat();
    }

    public void write(DataOutputStream out) throws IOException
    {
        out.writeUTF(getCode().name());
        out.writeUTF(name);
        out.writeFloat(posX); out.writeFloat(posY);
        out.writeFloat(angle);
        out.writeFloat(linVelX); out.writeFloat(linVelY);
        out.writeFloat(angVel);
        out.writeFloat(forceX); out.writeFloat(forceY);
        out.writeFloat(torque);
    }

    public Code getCode() {
        return Packet.Code.BODY_STATE;
    }

    public BodyState copy() {
        return new BodyState(this);
    }
}
